﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace IMCOM.Imagiality.ImageProcessing.Canvas2D.ROI
{
    class CrossROIHandle : RectangleROIHandle
    {
        private bool isNorth;
        private bool isWest;

        public CrossROIHandle(Point center, bool isNorth, bool isWest) : base(center)
        {
            this.isNorth = isNorth;
            this.isWest = isWest;
        }

        public override Rectangle Resize(Point mouseDelta, Rectangle rectangle)
        {
            /*Point firstPoint;
            Point secondPoint;

            if (isNorth)
            {
                if (isWest)
                {
                    firstPoint = new Point(rectangle.X + mouseDelta.X, rectangle.Y + mouseDelta.Y);
                    secondPoint = new Point(rectangle.Right, rectangle.Bottom);
                }
                else
                {
                    firstPoint = new Point(rectangle.X, rectangle.Y + mouseDelta.Y);
                    secondPoint = new Point(rectangle.Right + mouseDelta.X, rectangle.Bottom);
                }
            }
            else
            {
                if (isWest)
                {
                    firstPoint = new Point(rectangle.X + mouseDelta.X, rectangle.Y);
                    secondPoint = new Point(rectangle.Right, rectangle.Bottom + mouseDelta.Y);
                }
                else
                {
                    firstPoint = new Point(rectangle.X, rectangle.Y);
                    secondPoint = new Point(rectangle.Right + mouseDelta.X, rectangle.Bottom + mouseDelta.Y);
                }
            }

            rectangle = new Rectangle(firstPoint, new Size(secondPoint.X - firstPoint.X, secondPoint.Y - firstPoint.Y));
            return rectangle;*/

            Point newLocation = new Point(rectangle.Left, rectangle.Top);
            Size newSize = new Size(rectangle.Right - rectangle.Left, rectangle.Bottom - rectangle.Top);

            if (isNorth)
            {
                newLocation.Y += mouseDelta.Y;
                newSize.Height -= mouseDelta.Y;
            }
            else
            {
                newSize.Height += mouseDelta.Y;
            }

            if (isWest)
            {
                newLocation.X += mouseDelta.X;
                newSize.Width -= mouseDelta.X;
            }
            else
            {
                newSize.Width += mouseDelta.X;
            }

            return new Rectangle(newLocation, newSize);
        }

        public override Cursor GetCursor()
        {
            if ((isNorth && !isWest) || (!isNorth && isWest))
                return Cursors.SizeNESW;
            else if ((isNorth && isWest) || (!isNorth && !isWest))
                return Cursors.SizeNWSE;
            else
                return null;
        }
    }
}
